<?php
class GoodsAttrController extends Controller {
	private $db;
	private $gtid;
	//商品类型id
	public function __init() {
		$this -> db = K('GoodsAttr');
		$this -> gtid = Q('gtid', 0, 'intval');
		//分配商品类型gtid
		$this->assign('gtid',$this->gtid);
		if (!$this -> gtid) {
			$this -> error('商品类型GTID不能为空', "GoodsType/index");
		}
	}
	//属性列表
	public function index() {
		$data = $this -> db -> getAttrList($this -> gtid);
		$this -> assign('data', $data);
		$this -> display();
	}
	//添加属性
	public function add(){
		if(IS_POST){
			if($this->db->addAttr()){
				$this->success('属性添加成功 ',U('Index',array('gtid'=>$this->gtid)));
			}else{
				$this->error($this->db->error);
			}
		}else{
			$this->display();
		}
	}
	//编辑属性
	public function edit(){
		if(IS_POST){
			// p($_POST);die;
			if($this->db->editAttr()){
				$this->success('属性修改成功 ',U('Index',array('gtid'=>$this->gtid)));
			}else{
				$this->error($this->db->error);
			}
		}else{
			$gtid=Q('gtid','','intval');
			$aid=Q('aid','','intval');
			$gadata=M('goods_attr')->where('aid='.$aid)->all();	
			$gavdata=M('goods_attr_value')->where('attr_aid='.$aid)->all();
			$this->assign('gtid',$gtid);
			$this->assign('gadata',$gadata);
			$this->assign('gavdata',$gavdata);
			// p($gavdata);die;
			$this->display();
		}
	}
}












